﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace DHQGHN.PM0.Models.Admin
{
    public class UserInRoleModel
    {

        public string Email { get; set; }
        public int UserInRoleID { get; set; }

         [Remote("CheckExistUserInRole", "UserInRole", ErrorMessage = "Người dùng đã tồn tại trong vai trò", HttpMethod = "POST", AdditionalFields = "RoleID")]
        [Range(1, Int64.MaxValue, ErrorMessage = "Bạn cần chọn người dùng")]
        [Display(Name = "Người dùng")]
        public int UserID { get; set; }

        [Range(1, Int64.MaxValue, ErrorMessage = "Bạn cần chọn vai trò")]
        [Display(Name = "Vai trò")]
        public int RoleID { get; set; }

        [StringLength(150, ErrorMessage = "Độ dài tối đa là 150 ký tự")]
        [Display(Name = "Mô tả")]
        public string Descriptions { get; set; }

        public int IsActive { get; set; }

        public int RecordCount { get; set; }

        public string UserName { get; set; }
        public string FullName { get; set; }
        public string RoleName { get; set; }

        public int AppId { get; set; }

        public string UserCode { get; set; }

        public const string FIELD_RECORD_COUNT = "RecordCount";

        #region Field list from database
        public const string FIELD_ID = "MenuInRoleId";
        public const string FIELD_NAME = "NAME";
        public const string FIELD_CODE = "CODE";
        public const string FIELD_DESCRIPTIONS = "DESCRIPTIONS";
        public const string FIELD_EMAIL = "Email";
        public const string FIELD_FULL_NAME = "FullName";
        public const string FIELD_ROLE_NAME = "RoleName";
        public const string FIELD_USER_NAME = "UserName";
        public const string FIELD_USER_CODE = "UserCode";
        public const string FIELD_APP_ID = "AppId";
        #endregion

        public UserInRoleModel()
        {
            // TODO: Complete member initialization
        }

        public UserInRoleModel(DAL.Models.Admin.UserInRoleModel model)
        {
            // TODO: Complete member initialization
            Email = model.Email;
            FullName = model.FullName;
            UserInRoleID = model.UserInRoleID;
            UserID = model.UserID;
            RoleID = model.RoleID;
            RoleName = model.RoleName;
            UserName = model.UserName;
            UserCode = model.UserCode;
            Descriptions = model.Descriptions;
            RecordCount = model.RecordCount;
            AppId = model.AppId;
        }


        internal DAL.Models.Admin.UserInRoleModel toDALModel()
        {
            DAL.Models.Admin.UserInRoleModel model = new DAL.Models.Admin.UserInRoleModel
            {

                Email = Email,
                FullName = FullName,
                UserInRoleID = UserInRoleID,
                UserID = UserID,
                RoleID = RoleID,
                RoleName = RoleName,
                UserName = UserName,
                UserCode = UserCode,
                Descriptions = Descriptions,
                RecordCount = RecordCount,
                AppId = AppId
            };
            return model;
        }
    }
}